import { PostAgreeLog } from "~/api";

export const useContent = ({ emits }) => {
    const data = ref({});
    const visible = ref(false);
    const isChecked = ref(false);

    // 关闭
    const onClosed = () => {
        isChecked.value = false;
    };

    // 立即购买
    const onSubmitPay = () => {
        if (isChecked.value) {
            visible.value = false;
            emits("confirm");
        } else {
            Message().warning("请阅读购买协议并勾选！");
        }
    };

    watch(isChecked, () => {
        if (isChecked.value) {
            const ua = navigator.userAgent;
            PostAgreeLog({
                user_agent: ua,
                type: 2,
            });
        }
    });

    return {
        data,
        visible,
        isChecked,
        onClosed,
        onSubmitPay,
    };
};
